<?php
session_start();
/*
 * Session variables:
 * $_SESSION['type'] [string] = user type of the logged in user
 * $_SESSION['authorised'] [boolean] = whether or not the current user is logged in
 */
if (isset($_SESSION['authorised']) && $_SESSION['authorised'] == true) {
    if (isset($_SESSION['type'])) {
        if ($_SESSION['type'] == 'administrator') {
?>
            <html xmlns="http://www.w3.org/1999/xhtml">
                <head>
                    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                    <title> Manage Payment Mode </title>
                    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
                    <style>
                        .nav {
                            width:210px;
                            height:auto;
                            border:thin solid #09C;

                            margin-left: 10px;
                            text-align : center;}

                        .mainline {
                            width:712px;

                            height:auto;
                            text-align : center;}
                        </style>
                    </head>

                    <center>
                        <body bgcolor="#FFFFFF">
                            <div id="wrapper">
                            <div id="header">
    <h1></h1>
    </div>
    
    <div id="header2">
    	<h3></h3>
 	</div>
  

                            <div id="nav">
                              <?php include 'admin_navigation.php';?>
                            </div>
                            
                            <div id="mainline">
                                <h4> Manage Payment Mode </h4>
                                <div id="body">                                    
                                    <form name = "myform" action="admin_managepayroll.php" method="post">
                                        <table width="700" cellpadding="2" class="infotable" align="left">
                                           <tr height="40" bgcolor="#7B899B">
									            <th colspan="5">Tutors</th>
									        </tr>
									        <tr height="40" bgcolor="LightSteelBlue">
									            <th>Name</th>
									            <th>Payment Mode</th>
									            <th>Amount per Mode</th>
									            <th>Salary</th>
									            <th>Action</th>
									        </tr>
                                            <?php 
									            include ('connection.inc');
									            $sql = "SELECT * FROM teachers natural inner join users order by lastname, firstname";
									            $result = pg_query($sql);
									            
									            $count = pg_num_rows($result);
									            
									            if($count<1)
									            {
									            	echo "</table></form>";
									            	echo "No Tutors<br><br><br>";	
									            }
									            else
									            {
										            for($i = 0; $i < $count; $i++)
										            {
										                $firstname = pg_fetch_result($result, $i, 'lastname');
										                $lastname = pg_fetch_result($result, $i, 'firstname');
										                $mode = pg_fetch_result($result, $i, 'mode');
										                $per_mode = pg_fetch_result($result, $i, 'per_mode');
										                $teacher_id = pg_fetch_result($result, $i, 'teacher_id');
										                $salary = pg_fetch_result($result, $i, 'salary');
										                if($i%2==0)
										                {
										                	$bgcolor="#e8e8e8";
										                }
										                else
										                {
															$bgcolor="#f5f5f5";
										                }
										                
										                echo "<tr height=\"30\" bgcolor=$bgcolor><td><center>$lastname, $firstname</center></td><td><center>$mode</center></td><td><center>Php $per_mode</center></td><td><center>Php $salary</center></td><td><center><input type=submit name=\"action\" value=\"Edit $teacher_id\"  /></center></td></tr>";
										                
										                
										            }
										            echo "<tr height=\"50\"></tr></table></form>";
									            }
												?>
                                           
                                           
                                           <form action="admin_managepayment.php" method="post">
                                        <table width="712" cellpadding="2" class="infotable" align="left">
                                           <tr height="40" bgcolor="#7B899B">
									            <th colspan="5">Students</th>
									        </tr>
									        <tr height="40" bgcolor="LightSteelBlue">
									           <th>Name</th>
									            <th>Payment Mode</th>
									            <th>Amount per Mode</th>
									            <th>Balance</th>
									            <th>Action</th>
									        </tr>
									        <?php 
									        $sql = "SELECT * FROM students natural inner join users order by lastname, firstname";
									            $result = pg_query($sql);
									            
									            $count = pg_num_rows($result);
									            
									            if($count<1)
									            {
									            	echo "</table></form>";
									            	echo "No Students";	
									            }
									            else
									            {
										            for($i = 0; $i < $count; $i++)
										            {
										                $firstname = pg_fetch_result($result, $i, 'lastname');
										                $lastname = pg_fetch_result($result, $i, 'firstname');
										                $mode = pg_fetch_result($result, $i, 'mode');
										                $per_mode = pg_fetch_result($result, $i, 'per_mode');
										                $student_id = pg_fetch_result($result, $i, 'student_id');
										                $payment = pg_fetch_result($result, $i, 'payment');
										                if($i%2==0)
										                {
										                	$bgcolor="#e8e8e8";
										                }
										                else
										                {
															$bgcolor="#f5f5f5";
										                }
										                
										                echo "<tr height=\"30\" bgcolor=$bgcolor><td><center>$lastname, $firstname</center></td><td><center>$mode</center></td><td><center>Php $per_mode</center></td><td><center>Php $payment</center></td><td><center><input type=submit name=\"action\" value=\"Edit $student_id\"  /></center></td></tr>";
										                
										                
										            }
										            echo "</table></form>";
									            }
												?>
									        
                                        
                                
                            <p align="justify"><br /></p>
                        </div>

                        <br class="clearfloat"/>
                        <br />

</div>
 <div id="footer">
                            <p align="center">
                                Tutorial Business Manager: info@tbms.com <br />Credits/Engineers: Aquino, Chloebelle; Dela Cruz, Roy Erwin; Maliwanag, Ranyel Bryan; Manzano, Audrey Ann; Ng, Sheila Regine<br />
                                <br />copyright 2011</p>
                        </div>
                        </div>
                    </body>
                </center>
            </html>
<?php
        } elseif ($_SESSION['type'] == 'student') {
            header('Location: student_index.php');
            exit();
        } elseif ($_SESSION['type'] == 'tutor') {
            header('Location: tutor_index.php');
            exit();
        } elseif ($_SESSION['type'] == 'parent') {
            header('Location: parent_index.php');
            exit();
        }
    }
} else {
    header('Location: index.php');
}
?>
